package com.sright.bcard.enterprise.web.config;

import com.sright.bcard.enterprise.web.task.DayFirstLoginJob;
import lombok.extern.slf4j.Slf4j;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class QuartzConfig {

    @Bean
    public JobDetail updateDayFirstLoginDetail(){
        return JobBuilder.newJob(DayFirstLoginJob.class)//PrintTimeJob我们的业务类
                .withIdentity("DayFirstLoginJob")//可以给该JobDetail起一个id
                //每个JobDetail内都有一个Map，包含了关联到这个Job的数据，在Job类中可以通过context获取
//                .usingJobData("msg", "Hello Quartz")//关联键值对
                .storeDurably()//即使没有Trigger关联时，也不需要删除该JobDetail
                .build();
    }
    @Bean
    public Trigger updateDayFirstLoginTrigger() {
        log.info("修改每日登陆标识定时任务初始化成功...");
        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("0 0 0 */1 * ?");
//        CronScheduleBuilder cronScheduleBuilder = CronScheduleBuilder.cronSchedule("*/5 * * * * ?");
        return TriggerBuilder.newTrigger()
                .forJob(updateDayFirstLoginDetail())//关联上述的JobDetail
                .withIdentity("quartzTaskService")//给Trigger起个名字
                .withSchedule(cronScheduleBuilder)
                .build();
    }

}
